package com.oa.ylms.apps.common;

import java.util.Comparator;

import com.oa.ylms.apps.entity.EntityBase;

public class ContentComparator<T extends EntityBase> implements Comparator<T> {

	@Override
	public int compare(T o1, T o2) {
		T c1 = (T) o1;
		T c2 = (T) o2;
		int key_o1 = c1.getFirstKey();
		int key_o2 = c1.getFirstKey();

		int result = compareHelp(key_o1, key_o2);

		if (result == 0) {
			key_o1 = c1.getSecondKey();
			key_o2 = c2.getSecondKey();

			result = compareHelp(key_o1, key_o2);

		}

		return result;

	}

	private int compareHelp(int v1, int v2) {

		if (v1 > v2)
			return 1;
		else if (v1 == v2)
			return 0;
		else
			return -1;
	}

}
